import unittest
import os
import shutil
from utils.download_chrome_driver import Chrome
from global_conf import config
from XTestRunner import HTMLTestRunner

# 删除所有截图文件
def delete_all_screen_file():
    screen_file_list = os.listdir(config.screen_path)
    if len(screen_file_list) > 0:
        shutil.rmtree(config.screen_path)


if __name__ == '__main__':

    # 下载chrome驱动
    Chrome(os.path.join(config.BASE_DIR,'config.ini'))
    delete_all_screen_file()

    suite = unittest.TestLoader().discover("./cases", pattern="test*.py")

    # 确定生成报告的路径
    filePath = './report/HTMLTestReport.html'
    fp = open(filePath, 'wb')
    # 生成报告的Title,描述
    runner = HTMLTestRunner(
        stream=fp,
        title='自动化测试报告',
        tester='test'
    )
    # 运行测试用例
    runner.run(suite, rerun=1)


